//
//  XSTransmitBarView.swift
//  WeiDo
//
//  Created by XISHAN on 16/3/7.
//  Copyright © 2016年 XISHAN. All rights reserved.
//

import UIKit

class XSTransmitBarView: UIView {
   
    private var transmitBtn :UIButton!
    private var commentBtn:UIButton!
    private var likedBtn:UIButton!
    
    var statusViewModel : XSStatusViewModel?{
        
        didSet{
            transmitBtn.setTitle(statusViewModel?.transmitCountStr, forState: UIControlState.Normal)
            commentBtn.setTitle(statusViewModel?.commentsCountStr, forState: UIControlState.Normal)
            likedBtn.setTitle(statusViewModel?.attitudesCountStr, forState: UIControlState.Normal)
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){
        
        transmitBtn = addBottemButton("timeline_icon_retweet", title: "转发")
        commentBtn  = addBottemButton("timeline_icon_comment", title: "评论")
        likedBtn    = addBottemButton("timeline_icon_unlike", title: "赞")
        
        transmitBtn.snp_makeConstraints { (make) -> Void in
            make.top.leading.bottom.equalTo(self)
            make.width.equalTo(commentBtn)
        }
        commentBtn.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(transmitBtn.snp_trailing)
            make.top.bottom.equalTo(transmitBtn)
            make.width.equalTo(likedBtn)
        }
        likedBtn.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(commentBtn.snp_trailing)
            make.top.bottom.equalTo(commentBtn)
            make.trailing.equalTo(self)
        }
    }
    
    
    private func addBottemButton(imageNamed:String,title:String) -> (UIButton){
        
        let btn = UIButton()
        
        btn.setImage(UIImage(named: imageNamed), forState: .Normal)
        
        //设置title内容字体
        btn.setTitle(title, forState: .Normal)
        btn.titleLabel!.font = UIFont.systemFontOfSize(12)
        btn.setTitleColor(UIColor.lightGrayColor(), forState: .Normal)
      
        btn.setBackgroundImage(UIImage(named: "timeline_card_bottom_background_highlighted"), forState: .Highlighted)
        btn.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: .Normal)
        addSubview(btn)
        return btn
    }
}
